package com.nikkerball.apps.darkhorse.dev;

import com.nikkerball.apps.darkhorse.dao.BaseDao;
import com.nikkerball.apps.darkhorse.model.base.TouchableObject;
import com.nikkerball.apps.darkhorse.model.core.Classroom;
import com.nikkerball.apps.darkhorse.model.core.Learner;
import com.nikkerball.apps.darkhorse.model.core.Subject;
import com.nikkerball.apps.darkhorse.model.core.Topic;
import com.nikkerball.apps.darkhorse.model.security.User;
import org.joda.time.LocalDate;

/**
 * TODO: Document class
 *
 * @author marius (created on 2010-11-28)
 */
public class TestDataLoader {

    // ----- instance fields -----

    private BaseDao baseDao;

    // ----- constructors -----

    public TestDataLoader(BaseDao baseDao) {
        this.baseDao = baseDao;
    }

    // ----- public methods -----

    public void loadData() {
        // Create some Class Rooms
        loadClassRoom("Maple");
        loadClassRoom("Mulberry");
        loadClassRoom("Elm");

        // Create some Learners
        loadLearner("Tom", "Jones");
        loadLearner("Dick", "Bird");
        loadLearner("Harry", "Houdini");

        // Create some Subjects
        loadSubject("Literacy");
        loadSubject("Numeracy");
        loadSubject("Topic/Science/ICT");
        loadSubject("PE");
        loadSubject("Art");
        loadSubject("Music");

        // Create some Topics
        loadTopic("Social");
        loadTopic("Head");

        // Create some User
        loadUser("Isaac", "Newton");
        loadUser("Thomas", "Edison");
        loadUser("Albert", "Einstein");


    }

    // ----------

    @SuppressWarnings({"MagicNumber"})
    private void loadLearner(String name, String surname) {
        Learner learner = new Learner(name, surname);
        learner.setBirthDate(new LocalDate(2007, 3, 30));
        save(learner);
    }

    private void loadClassRoom(String name) {
        Classroom classroom = new Classroom(name);
        save(classroom);
    }

    private void loadSubject(String name) {
        Subject subject = new Subject(name);
        save(subject);
    }

    private void loadTopic(String name) {
        Topic topic = new Topic(name);
        save(topic);
    }

    private void loadUser(String name, String surname) {
        User user = new User(name, surname, name + "." + surname, name + "." + surname + "@darkhorse", "black");
        save(user);
    }

    private void save(TouchableObject touchableObject) {
        this.baseDao.add("dev", touchableObject);
    }

}
